﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainDrive.Core.Interface;

namespace Esb.Domain.DomainObjects
{
    /// <summary>
    /// 环境领域对象，非聚合根
    /// </summary>
    public class EnvironmentDo
    {
        /// <summary>
        /// 构造函数传入环境类型
        /// </summary>
        /// <param name="type"></param>
        public EnvironmentDo(EnvironmentType type)
        {
            this.EnvironmentType = type;
        }

        public EnvironmentDo()
        {
 
        }

        /// <summary>
        /// TODO：避免循环引用
        /// </summary>
        //public ServiceDo ServiceDo
        //{
        //    get;
        //    set;
        //}

        /// <summary>
        /// 环境
        /// </summary>
        public EnvironmentType EnvironmentType { get; set; }

        /// <summary>
        /// 手动设置的服务地址
        /// </summary>
        public string RawServiceUrl { get; set; }

        /// <summary>
        /// 获取服务地址，例如：http://erp.rest.dotnet.dev.xxx.com/
        /// </summary>
        /// <returns></returns>
        public string GetServiceUrl()
        {
            //如果手动设置服务地址为空，则根据规则生成地址，已废弃
            if (string.IsNullOrEmpty(RawServiceUrl))
            {
                //return string.Format("{0}://{1}.{2}.{3}.{4}", this.ServiceDo.Protocol,
                //    this.ServiceDo.Architecture, this.ServiceDo.Platform, EnvironmentType.ToString(), this.ServiceDo.DomainName);
                ////例如：http://Rest.DotNet.Test.xxx.com

                return "";
            }
            else
            {
                return RawServiceUrl;
            }
        }
    }

    public enum EnvironmentType
    {
        //开发
        Dev,

        //测试
        Test,

        //预发布
        Uat,

        //生产
        Prd
    }
}
